package com.umpay.config;

import com.umpay.exception.RedirectBusiException;
import com.umpay.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;


/**
 * @ClassName: RedirectBusiExceptionHandler  
 * @Description: 统一异常处理器
 * @author zhangtao  
 * @date Sep 21, 2017 9:00:03 PM
 */
@ControllerAdvice
class RedirectBusiExceptionHandler {
     
	@Autowired
	private PropertyUtil propertyUtil;
	@ExceptionHandler(value = RedirectBusiException.class)
	public ModelAndView defaultErrorHandler(RedirectBusiException e) throws Exception {
		ModelAndView model = new ModelAndView();
        model.setView(new RedirectView(propertyUtil.getProperty("Url.merAccess.outer.base.url") + "/merAccess/common/error"));
        model.addObject("errorCode", e.getCode());
        model.addObject("errorMsg", e.getMsg());
		return model;
	}
}
